#!/bin/sh
#
# Runs pipo to create a Cadence DFII library
# from final.gds2 from SOC Encounter

# Customize here:
echo /cds/local/osu_stdcells/lib/tsmc025/lib
techlibsDir= /cds/local/lib/NCSU_TechLib_tsmc03
osucellsDir= /cds/local/osu_stdcells/lib/tsmc025/lib
echo $techlibsDir
echo $osucellsDir
#############################################################

sourceFile=final.gds2

/bin/echo "Checking if $sourceFile exists......\c"
if (test ! -f $sourceFile ) then
    echo "FAILED"
    echo $sourceFile does not exist!
    echo Please run Encountner first or rerun if necessary
    exit 127
fi
echo "OK"

/bin/echo "Determining top-level name.........\c"
toplevel=`grep "set my_toplevel" encounter.conf | awk '{print $3;}'`
#toplevel='dco_control'
df2LibName=$toplevel

echo "OK ($toplevel)"

#/bin/echo "Creating new DFII library..........\c"
#mkdir $df2LibName
#cp $sourceDir/cdsinfo.tag $df2LibName
#cp $sourceDir/prop.xx     $df2LibName
#echo "OK ($df2LibName)"


/bin/echo "Creating PIPO script file..........\c"
echo  streamInKeys = list\(nil                                     >pipotemp.scr
echo          \'runDir                          \".\"             >>pipotemp.scr
echo          \'inFile                          \"final.gds2\"    >>pipotemp.scr
echo          \'primaryCell                     \"\"              >>pipotemp.scr
echo          \'libName                         \"$df2LibName\"   >>pipotemp.scr
echo          \'techfileName                    \"\"              >>pipotemp.scr
echo          \'scale                           0.001000          >>pipotemp.scr
echo          \'units                           \"micron\"        >>pipotemp.scr
echo          \'errFile                         \"PIPO.LOG\"      >>pipotemp.scr
echo          \'refLib                          t                 >>pipotemp.scr
echo          \'hierDepth                       32                >>pipotemp.scr
echo          \'maxVertices                     1024              >>pipotemp.scr
echo          \'checkPolygon                    nil               >>pipotemp.scr
echo          \'snapToGrid                      t                 >>pipotemp.scr
echo          \'arrayToSimMosaic                t                 >>pipotemp.scr
echo          \'caseSensitivity                 \"preserve\"      >>pipotemp.scr
echo          \'zeroPathToLine                  \"lines\"         >>pipotemp.scr
echo          \'convertNode                     \"ignore\"        >>pipotemp.scr
echo          \'skipUndefinedLPP                t                 >>pipotemp.scr
echo          \'ignoreBox                       nil               >>pipotemp.scr
echo          \'reportPrecision                 nil               >>pipotemp.scr
echo          \'runQuiet                        nil               >>pipotemp.scr
echo          \'saveAtTheEnd                    nil               >>pipotemp.scr
echo          \'noWriteExistCell                nil               >>pipotemp.scr
echo          \'NOUnmappingLayerWarning         nil               >>pipotemp.scr
echo          \'cellMapTable                    \"\"              >>pipotemp.scr
echo          \'layerTable                      \"gds2_icfb.map\" >>pipotemp.scr
echo          \'textFontTable                   \"\"              >>pipotemp.scr
echo          \'restorePin                      0                 >>pipotemp.scr
echo          \'propMapTable                    \"\"              >>pipotemp.scr
echo          \'propSeparator                   \",\"             >>pipotemp.scr
echo          \'userSkillFile                   \"\"              >>pipotemp.scr
echo          \'rodDir                          \"\"              >>pipotemp.scr
echo          \'refLibOrder                     \"$sourceLib\"    >>pipotemp.scr
echo          \'keepStreamCells                 nil               >>pipotemp.scr
echo  \)  >>pipotemp.scr
echo "OK"

/bin/echo "Running PIPO (GDS Stream-In).......\c"
pipo strmin pipotemp.scr
grep "* Warning *" PIPO.LOG
grep "* Fatal *" PIPO.LOG
echo ""
echo ""

/bin/echo "Running IHDL (Verilog In)..........\c"
echo ""
ihdl -param ihdl_file -precompilelibrary  OSU_stdcells_tsmc025 final.v
echo ""

/bin/echo "Cleaning up........................\c"
/bin/rm -f pipotemp.scr
if (test -f cds.lib.piposave) then 
   mv cds.lib.piposave cds.lib 
fi
echo "OK"
echo "Good by."

